package com.srxz.personnelsystem;

import com.srxz.personnelsystem.util.UnauthorizedException;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @作者：wgchao
 * @时间：9:16 2019/2/25 0025
 * @用途：检查session
 **/
@Component
public class SessionInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception{
        HttpSession session = request.getSession();
        String uri = request.getRequestURI();
        if (uri.startsWith("/personnel")) {
            if(session.getAttribute("userinfo")==null ){
                System.out.println("----------------");
                response.sendRedirect(request.getContextPath() + "/login.html");
                return false;
            }
        }

        return true;
    }
}
